<template>
  <div class="home">
    <div class="bg" :style="{ background: bgColor }"></div>
    <div class="container">
      <div class="logo">
        <div class="logo-bg"></div>
      </div>
      <div class="colors">
        <div
          class="color-box"
          :key="index"
          v-for="(item, index) in colorList"
          @click="getColorItem(item)"
          v-clipboard:copy="item.hex"
          v-clipboard:success="onCopy"
        >
          <color-item :item="item" />
        </div>
      </div>
      <div class="content">
        <div class="content-color">
          <div class="circle-container" v-for="(item, index) in cmyk" :key="item.title">
            <div class="circle-title">{{item.title}}</div>
            <div class="circle" :style="{color: item.color}">
              {{currentCmky[index]}}
            </div>
            <div class="circle-right">
              <div class="line"
                v-if="currentCmky[index] >= 50"
                :style="{transform: `rotate(${180}deg)`}"></div>
              <div class="line"
                v-else
                :style="{transform: `rotate(${3.6 * currentCmky[index]}deg)`}"></div>
            </div>
            <div class="circle-left">
              <div class="line"
              v-if="currentCmky[index] >= 50"
              :style="{transform: `rotate(${3.6 * currentCmky[index]}deg)`}"></div>
              <div class="line"
              v-else
              :style="{transform: `rotate(${180}deg)`}"></div>
            </div>
          </div>
        </div>
        <div class="content-num">
          <num-rgb title="R" ref="num" :numbers="RGB[0]" />
          <num-rgb title="G" :numbers="RGB[1]" />
          <num-rgb title="B" :numbers="RGB[2]" />
        </div>
        <div class="content-name">
          <div class="content-name__chinese">
            {{chineseName}}
          </div>
          <div class="content-name__pinyin">
            {{chinsesPinyin.toUpperCase()}}
          </div>
        </div>
        <div class="tip-box" v-show="tipShow">
          <div class="tip">复制成功，{{bgColor}}！</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import ColorItem from "../components/ColorItem";
import NumRgb from '../components/Num'
import COLORS from './colors'
export default {
  name: "Home",
  components: {
    ColorItem,
    NumRgb
  },
  data() {
    return {
      colorList: COLORS,
      bgColor: "#bbb",
      cmyk: [
        {
          title: 'C',
          color: '#0093D3'
        },
        {
          title: 'M',
          color: '#CC006B'
        },
        {
          title: 'Y',
          color: '#FFF10C'
        },
        {
          title: 'K',
          color: '#000000'
        },
      ],
      currentCmky: [0, 0, 0, 0],
      RGB: [0, 0, 0],
      chineseName: '中国色',
      chinsesPinyin: 'ZHONGGUOSE',
      tipShow: false
    };
  },
  methods: {
    getColorItem(item) {
      this.bgColor = item.hex;
      this.currentCmky = item.CMYK
      this.RGB = item.RGB
      this.chineseName = item.name
      this.chinsesPinyin = item.pinyin
      this.tipShow = true
      setTimeout(() => {
        this.tipShow = false
      }, 1000)
      document.title = `${this.chineseName} - 中国色 - 中国传统颜色`
    },
    onCopy(e) {
      console.log(e.text)
    }
  }
};
</script>
<style lang="scss" scoped>
.home {
  .bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url("../assets/images/bg.png") #bbb;
    transition: all 1s linear;
  }
  .container {
    width: 960px;
    height: 100%;
    margin: 40px auto;
    position: relative;
    .logo {
      position: absolute;
      left: 909px;
      .logo-bg {
        width: 60px;
        height: 520px;
        background: url("../assets/images/logo.png") no-repeat;
        position: fixed;
      }
    }
    .colors {
      width: 490px;
      height: 100%;
      position: absolute;
      left: -23px;
      top: 0;
      display: flex;
      justify-content: flex-start;
      flex-wrap: wrap;
      .color-box {
        width: 50px;
        height: 284px;
        margin-right: 15px;
        margin-top: 20px;
      }
    }
    .content {
      position: absolute;
      left: 434px;
      top: 20px;
      height: 507px;
      width: 410px;
      margin-left: 70px;
      .content-color {
        position: fixed;
        width: 100px;
        .circle-container {
          height: 86px;
          position: relative;
          width: 50px;
          z-index: 500;
          border-top: 1px solid #fff;
          &:nth-child(2) {
            .circle-right,.circle-left {
              .line {
                background-position: 0 -50px;
              }
            }
          }
          &:nth-child(3) {
            .circle-right,.circle-left {
              .line {
                background-position: 0 -100px;
              }
            }
          }
          &:nth-child(4) {
            .circle-right,.circle-left {
              .line {
                background-position: 0 -150px;
              }
            }
          }
          .circle-title {
            height: 26px;
            line-height: 26px;
            color: #fff;
            font-size: 10px;
          }
          .circle {
            background: url("../assets/images/circle.png") no-repeat;
            display: block;
            height: 50px;
            left: 0;
            position: absolute;
            top: 26px;
            width: 50px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #fff;
            font-family: sans-serif;
            font-size: 24px;
            font-weight: 300;
          }
          .circle-right {
            position: absolute;
            left: 0;
            top: 26px;
            width: 50px;
            height: 50px;
            mask-image: url("../assets/images/circle_r.png");
            .line {
              display: block;
              height: 50px;
              left: 1px;
              position: absolute;
              top: 0;
              width: 50px;
              background: url("../assets/images/colorBox.png") no-repeat;
              background-position:  0 0;
              transform: rotate(180deg);
              transition: all 0.5s linear;
            }
          }
          .circle-left {
            position: absolute;
            left: 0;
            top: 26px;
            width: 50px;
            height: 50px;
            mask-image: url("../assets/images/circle_l.png");
            .line {
              display: block;
              height: 50px;
              left: 1px;
              position: absolute;
              top: 0;
              width: 50px;
              background: url("../assets/images/colorBox.png") no-repeat;
              background-position:  0 0;
              transform: rotate(180deg);
              transition-delay: 0.5s;
              transition: all 0.5s linear;
            }
          }
        }
      }
      .content-num {
        position: fixed;
        top: 410px;
        width: 50px;
      }
      .content-name {
        position: fixed;
        top: 100px;
        color: #fff;
        .content-name__chinese {
          font-family: 'lixukexingshu1b969ad7dc1c3e5';
          font-weight: normal;
          font-size: 100px;
          //font-family: cursive;
          color: #fff;
          margin: 0 auto;
          width: 100px;
          text-align: center;
          background-position: center top;
          background-repeat: no-repeat;
        }
        .content-name__pinyin {
          font-size: 16px;
          width: 500px;
          margin-top: 30px;
          text-align: center;
          font-family: Georgia;
          font-weight: bold;
          -webkit-font-smoothing: antialiased;
        }
      }
      .footer {
        position: fixed;
        width: 500px;
        bottom: 0;
        text-align: center;
        color: #fff;
        font-size: 10px;
        font-family: cursive;
      }
      .tip-box {
        width: 500px;
        position: fixed;
        top: 40px;
        .tip {
          // position: fixed;
          // top: 40px;
          // left: 1200 * $vw;
          width: 180px;
          text-align: center;
          margin: 0 auto;
          padding: 20px;
          border-radius: 5px;
          color: #fff;
          border: 1px solid #fff;
        }
      }

    }
  }
}
</style>
